--EasyLoader v0.2
--by Gotoxy Ported by gReY


hotkey = 76 --ON OFF key is L
AutoHeal = 1 --set 0 if u don't need it
AutoMana = 1 --set 0 if u don't need it
AutoRpot = 1 --set 0 if u don't need it
AutoBpot = 1 --set 0 if u don't need it

---------------------------------------
-- DO NOT CHANGE THE REST OF THIS CODE--
---------------------------------------
REDcd = 0 --do not change
BLUEcd = 0 --do not change
status = true
function OnWndMsg(msg, keycode)
    if msg == KEY_DOWN and keycode == hotkey then
        if status == true then
            status = false
            PrintChat(" >> EasyKayle OFF.")
        else
            status = true
            PrintChat(" >> EasyKayle ON.")
        end
    end
end

function OnTick()
    if not tick or os.clock() * 1000 - tick > 250 then
        tick = os.clock() * 1000
        local REDkey
        local BLUEkey
        local ItemSlot = { ITEM_1, ITEM_2, ITEM_3, ITEM_4, ITEM_5, ITEM_6, }

        for i = 1, 6, 1 do
            if player:getInventorySlot(ItemSlot[i]) == 2004 then BLUEkey = ItemSlot[i]
            elseif player:getInventorySlot(ItemSlot[i]) == 2003 then REDkey = ItemSlot[i]
            end
        end


        if MANAkey ~= nil and player:CanUseSpell(MANAkey) == READY and AutoMana == 1 and status == true then
            local mana = player.mana / player.maxMana --calc mana
            if mana < 0.2 then
                CastSpell(MANAkey)
            end
        end

        if HEALkey ~= nil and player:CanUseSpell(HEALkey) == READY and AutoHeal == 1 and status == true then
            local playerHealth = player.health / player.maxHealth --calc hp
            if playerHealth < 0.35 then
                CastSpell(HEALkey)
            end
        end

        if BLUEkey ~= nil and BLUEcd == 0 and AutoBpot == 1 and status == true then
            local playermanaa = player.mana / player.maxMana
            if playermanaa < 0.5 then
                CastSpell(BLUEkey)
                BLUEcd = tick + (13 * 1000)
            end
        else
            if BLUEcd ~= 0 and BLUEcd < tick then
                BLUEcd = 0
            end
        end

        if REDkey ~= nil and REDcd == 0 and AutoRpot == 1 and status == true then
            local playerHealth = player.health / player.maxHealth
            if playerHealth < 0.7 then
                CastSpell(REDkey)
                REDcd = tick + (13 * 1000)
            end
        else
            if REDcd ~= 0 and REDcd < tick then
                REDcd = 0
            end
        end
    end
end

function OnLoad()
    if player:GetSpellData(SUMMONER_1).name == "SummonerHeal" then
        HEALkey = SUMMONER_1
    elseif player:GetSpellData(SUMMONER_2).name == "SummonerHeal" then
        HEALkey = SUMMONER_2
    end
    if player:GetSpellData(SUMMONER_1).name == "SummonerMana" then
        MANAkey = SUMMONER_1
    elseif player:GetSpellData(SUMMONER_2).name == "SummonerMana" then
        MANAkey = SUMMONER_2
    end
    if not HEALkey and not MANAkey then
        OnWndMsg, OnTick = function() end, function() end
        return
    else
        PrintChat(" >>Gotoxy: EasyLaner loaded. ")
    end

end
